<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript">
        function selectAll(){
            var a = document.getElementsByName("hobby");
            //document.getElementsByName 是通过name获取标签元素
            for (var i = 0; i < a.length; i++){
                a[i].checked = true;
            }
        }
        function selectNon(){
            var a = document.getElementsByName("hobby");
            for (var i = 0; i < a.length; i++){
                a[i].checked = false;
            }
        }
        function agaist(){
            var a = document.getElementsByName("hobby");
            for (var i = 0; i < a.length; i++){
                a[i].checked = !a[i].checked;
            }
        }
    </script>
</head>
<body>
    <input type="checkbox" name="hobby" checked="checked" value="java">java
    <input type="checkbox" name="hobby" value="C#">C#
    <input type="checkbox" name="hobby" value="C++">C++
    <br/>
    <button onclick="selectAll();">全选</button>
    <button onclick="selectNon();">全不选</button>
    <button onclick="agaist();">反选</button>
</body>
</html>